package com.zzb.service;

import com.zzb.dao.NewsDao;
import com.zzb.model.NewsModel;
import com.zzb.model.NewsTypeModel;

import java.util.ArrayList;
import java.util.List;

public class NewsService {
    public List<NewsModel> getNewsModelList(String newsType) {
        List<NewsModel> list = new ArrayList<>();
        for (NewsModel newsModel : NewsDao.newsModelList) {
            if (newsModel.getNewsTypeModel().getChName().equals(newsType)) {
                list.add(newsModel);
            }
        }
        return list;
    }
    public List<NewsModel> getNewsModelList(String newsType,int num) {
        List<NewsModel> list = new ArrayList<>();
        int count = 0;
        for (NewsModel newsModel : NewsDao.newsModelList) {
            if (newsModel.getNewsTypeModel().getChName().equals(newsType)) {
                list.add(newsModel);
                count++;
                if(count == num){
                    break;
                }
            }
        }
        return list;
    }

    public List<NewsTypeModel> getNewsTypeModelList() {
        return NewsDao.newsTypeModelList;
    }
}
